<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../../commons/taglibs.jsp"%>
<%@ include file="../../commons/list.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta charset="utf-8">
  <title>用户管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <style type="text/css">
  	input{
  		width: 200px;
  		display: inline;
  	}
  </style>
</head>

<body>
 <div>
	<div style="padding: 50px;padding-top: 20px">
		<form class="layui-form layui-form-pane"  action="">
		<input type="hidden" id='entityId' name='entityId' value="${sysMenu.id }">
		<input type="hidden"  name='id' value="${sysMenu.id }">
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
		    <label class="layui-form-label">菜单名称</label>
		     <div class="layui-input-block">
		      <input type="text" name="menuname" value="${sysMenu.menuname}" required  lay-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
		     <label class="layui-form-label">父节点id</label>
		    <div class="layui-input-block">
		      <input type="text" name="parentid" value="${sysMenu.parentid }" required  lay-verify="required" placeholder="请输入父节点id" autocomplete="off" class="layui-input">
		    </div>
		  </div>
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 60px">
			<label class="layui-form-label">菜单地址</label>
			 <div class="layui-input-block">
		      <input type="text" name="menuurl" value="${sysMenu.menuurl }" placeholder="请输入菜单地址" autocomplete="off" class="layui-input">
		     </div>
	      </div>  
	      
	      <div class="layui-form-item" style="width: 85%;padding-left: 60px">
			<label class="layui-form-label">菜单图标</label>
			 <%-- <div class="layui-input-block">
		      <input type="text" name="icon" value="${sysMenu.icon }" required  lay-verify="required" placeholder="请输入图标" autocomplete="off" class="layui-input">
		     </div> --%>
		     <div class="layui-input-block">
                <input type="text" id="iconPicker" name="icon" lay-filter="iconPicker" class="layui-input">
            </div>
	      </div>  
		  
		  <div class="layui-form-item" style="width: 85%;padding-left: 150px;padding-top: 30px">
		    <div class="layui-input-block">
		      <button class="layui-btn" id='tjsub' lay-submit lay-filter="formDemo">立即提交</button>
		      <a class="layui-btn" onclick="closeWindow()"><i class="layui-icon">&#xe65c;</i>返回</a>
		    </div>
		  </div>
		</form>
	</div>
 </div> 

<script>
layui.config({
	base: '<%=basePath%>common/plugins/iconpicker/'
}).extend({
    iconPicker: 'iconPicker'
}).use(['form','iconPicker'], function(){
	  var form = layui.form,
	  	  iconPicker = layui.iconPicker;
	  	  
	  	iconPicker.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // 数据类型：fontClass/unicode，推荐使用fontClass
            type: 'fontClass',
            // 是否开启搜索：true/false
            search: true,
            // 是否开启分页
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            }
        });
	  	
	 /**
      * 选中图标 （常用于更新时默认选中图标）
      * @param filter lay-filter
      * @param iconName 图标名称，自动识别fontClass/unicode
      */
	  iconPicker.checkIcon('iconPicker', '${sysMenu.icon }');
	  	
	  form.on('submit(formDemo)', function(data){
		  //提交成功后禁用按钮
		  $("#tjsub").css("pointer-events","none"); 
		  $.post('<%=basePath%>controller/sysMenu/save',data.field,function(data){
			  if(data == '1'){
				  $("#tjsub").css("pointer-events","auto");
				  layer.msg('提交失败', {time:1000});
			  }
			  if(data == '0'){
				  layer.msg('提交成功', {time:1000});
				  setTimeout("layer.closeAll()",1000);
				  //window.setTimeout(refreshCount, 1000 * 5);
				  //调用刷新页面
				  setTimeout("parent.location.reload()",2000);
				  
			  }
			  if(data == '2'){
				  $("#tjsub").css("pointer-events","auto");
				  layer.msg('父节点不存在，请重新填写！', {time:1000});
			  }
			  if(data == '3'){
				  $("#tjsub").css("pointer-events","auto");
				  layer.msg('提交失败，目前只支持二级菜单', {time:1000});
			  }
		  })
		  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
	});    

//返回按钮事件
function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
} 
</script>
</body>
</html>
